package com.csu.mypetstore.api.vo;

import com.csu.mypetstore.api.entity.Item;
import lombok.Data;

import java.math.BigDecimal;

@Data
public class CartmessageVO {
    private int cartId;
    private String username;
    private String itemId;
    private int quantity;
    private BigDecimal listPrice;
    private boolean inStock;
    private BigDecimal total;
    private String productId;
    private Item item;

    private void calculateTotal() {
        if (item != null && item.getListPrice() != null) {
            total = item.getListPrice().multiply(new BigDecimal(quantity));
        } else {
            total = null;
        }
    }

    public void incrementQuantity() {
        quantity++;
        calculateTotal();
    }
}
